package com.lz.yz.base.config;

import org.apache.catalina.connector.Connector;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;

/**
 * ajp使用二进制格式来传输可读性文本
 */
//@Configuration
//@ConfigurationProperties(prefix = "server.tomcat.ajp", locations = "classpath:application.yml")
public class AJPConfigration {

    private Integer port;

    private Boolean remoteAuthentication;

    private Boolean enabled;

    public void setPort(Integer port) {
        this.port = port;
    }

    public void setRemoteAuthentication(Boolean remoteAuthentication) {
        this.remoteAuthentication = remoteAuthentication;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    @Bean
    public EmbeddedServletContainerFactory servletContainer() {

        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
        if (enabled)
        {
            Connector ajpConnector = new Connector("AJP/1.3");
            ajpConnector.setProtocol("AJP/1.3");
            ajpConnector.setPort(Integer.valueOf(port));
            ajpConnector.setSecure(false);
            ajpConnector.setAllowTrace(false);
            ajpConnector.setScheme("http");
            tomcat.addAdditionalTomcatConnectors(ajpConnector);
        }
        return tomcat;
    }
}
